<template>
  <div class="app-container">
    <el-row :gutter="24" class="mb8">
      <el-col :span="8">
        认证成绩单
      </el-col>
      <el-col :span="16" style="text-align: right;">
        <el-button
          type="primary"
          icon="el-icon-refresh"
          size="mini"
          @click="$router.go(0)"
        >刷新</el-button
        >
      </el-col>
    </el-row>

    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>筛选列表</span>
      </div>
      <div class="text item">
        <el-form
          :model="queryParams"
          ref="queryForm"
          :inline="true"
          label-width="120px"
        >
          <el-form-item label="姓名/身份证号：" prop="message">
            <el-input
              v-model="queryParams.message"
              placeholder="请输入姓名/身份证号"
              clearable
              size="small"
            />
          </el-form-item>
          <el-form-item>
            <el-button
              type="primary"
              icon="el-icon-search"
              size="mini"
              @click="handleQuery"
              v-hasPermi="['toolsystem:report:query']"
            >搜索</el-button
            >
            <el-button
              type="primary"
              icon="el-icon-refresh"
              size="mini"
              @click="resetQuery"
            >重置</el-button
            >
          </el-form-item>
        </el-form>
      </div>
    </el-card>

    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span>成绩单列表</span>
        <el-button
          type="primary"
          size="mini"
          style="float: right;"
          @click="handleExport"
          v-hasPermi="['toolsystem:report:export']"
        >批量下载</el-button
        >
      </div>
      <div class="text item">
        <el-table v-loading="loading" :data="orderList">
          <el-table-column type="index" width="80" align="center" label="编号" />
          <el-table-column label="姓名" align="center" prop="studentName" />
          <el-table-column label="身份证号" align="center" prop="idCard" />
          <el-table-column label="省份" align="center" prop="provinceName" />
          <el-table-column label="中学" align="center" prop="schoolName" />
          <el-table-column label="考试名称" align="center" prop="examUuidName" />
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-view"
                @click="handleView(scope.row)"
                v-hasPermi="['toolsystem:report:view']"
              >查看</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-download"
                class="btn_sort"
                @click="handleExportOne(scope.row)"
                v-hasPermi="['toolsystem:report:export']"
              >下载</el-button>
            </template>
          </el-table-column>
        </el-table>
      </div>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-card>
  </div>
</template>

<script>
  import { checkOrder } from "@/api/toolsystem/report"
  import { downLoadZip } from "@/utils/zipdownload";

  export default {
    name: "Label",
    components: {},
    data() {
      return {
        // 遮罩层
        loading: true,
        // 查询参数
        queryParams: {
          pageNum: 1,
          pageSize: 10,
          message: null // 身份证
        },
        // 总条数
        total: 0,
        // 标签配置表格数据
        orderList: [],
        isChecked: false // 防重复点击
      };
    },
    created() {
      this.getList();
    },
    methods: {
      // 筛选表单重置
      resetQuery() {
        this.$refs["queryForm"].resetFields()
        this.getList();
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 查询订单配置列表 */
      getList() {
        this.loading = true;
        checkOrder(this.queryParams)
          .then(response => {
            console.log(response)
            if (response.code != 200) {
              this.loading = false;
              return this.msgError(response.msg);
            }
            this.orderList = response.data;
            this.total = this.orderList.length;
            this.loading = false;
          })
          .catch(error => {
            this.loading = false;
            console.log(error);
          });
      },
      // 查看按钮操作
      handleView(row){
        console.log(row)
      },
      /** 导出按钮操作 */
      handleExport() {
        const query = this.queryParams.message
        if(query){
          downLoadZip(`/tools-authreport/downloadAll/${query}`, "成绩单-All");
        }
      },
      handleExportOne(row) {
        const idCard = row.idCard;
        const examUuid = row.examUuid
        const dateTime = examUuid?examUuid.replace(/[^0-9]/ig,""):NaN;
        downLoadZip(`/tools-authreport/downloadOne/${idCard}/${examUuid}`, "成绩单-"+dateTime);
      }
    }
  };
</script>

<style lang="scss">
  @import "@/assets/styles/card.scss";
</style>

